package eg.com.itiga.business.factory;

import java.util.ResourceBundle;

import eg.com.itiga.business.base.BaseService;
import eg.com.itiga.business.company.CompanyService;
import eg.com.itiga.business.company.RegCompanyService;
import eg.com.itiga.business.exception.BusinessException;
import eg.com.itiga.business.graph.GraphService;

import eg.com.itiga.business.itian.BranchService;
import eg.com.itiga.business.itian.DepartmentService;

import eg.com.itiga.business.itian.ItianService;
import eg.com.itiga.business.report.ReportService;
import eg.com.itiga.business.role.RoleService;
import eg.com.itiga.business.user.UserService;


/**
 * @author Ramadanco88
 *
 */
public class BusinessFactory {
	public static BaseService createBaseService() throws BusinessException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
		
		String baseServiceFullyQualifiedName = resourceBundle.getString("BaseService");
		
		try {
			return (BaseService)Class.forName(baseServiceFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new BusinessException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		}		
	}
	public static BranchService createBranchService() throws BusinessException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
		
		String baseServiceFullyQualifiedName = resourceBundle.getString("BranchService");
		
		try {
			return (BranchService)Class.forName(baseServiceFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new BusinessException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		}		
	}

	public static DepartmentService createDepartmentService() throws BusinessException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
		
		String baseServiceFullyQualifiedName = resourceBundle.getString("DepartmentService");
		
		try {
			return (DepartmentService)Class.forName(baseServiceFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new BusinessException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		}		
	}

	
	public static RoleService createRoleService() throws BusinessException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
		
		String roleServiceFullyQualifiedName = resourceBundle.getString("RoleService");
		
		try {
			return (RoleService)Class.forName(roleServiceFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new BusinessException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		}		
	}
	
	public static RegCompanyService createRegCompanyService() throws BusinessException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
		
		String roleServiceFullyQualifiedName = resourceBundle.getString("RegCompanyService");
		
		try {
			return (RegCompanyService)Class.forName(roleServiceFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new BusinessException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		}	
	}
	
	public static UserService createUserService() throws BusinessException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
		
		String userServiceFullyQualifiedName = resourceBundle.getString("UserService");
		
		try {
			return (UserService)Class.forName(userServiceFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new BusinessException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new BusinessException("Factory Failed");
		}
		
	}

	public static CompanyService createCompanyService() throws BusinessException {
        ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
       
        String baseServiceFullyQualifiedName = resourceBundle.getString("CompanyService");
       
        try {
            return (CompanyService)Class.forName(baseServiceFullyQualifiedName).newInstance();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           
            throw new BusinessException("Factory Failed");
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        }
       
    }
    
	public static ItianService createItianService() throws BusinessException {
        ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
        
        String itianServiceFullyQualifiedName = resourceBundle.getString("ItianService");
        
        System.out.println(itianServiceFullyQualifiedName);
        try {
            return (ItianService)Class.forName(itianServiceFullyQualifiedName).newInstance();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           
            throw new BusinessException("Factory Failed");
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        }
       
    }
	public static ReportService createReportService() throws BusinessException
	{
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
        
        String ReportServiceFullyQualifiedName = resourceBundle.getString("ReportService");
        
        System.out.println(ReportServiceFullyQualifiedName);
        try {
            return (ReportService)Class.forName(ReportServiceFullyQualifiedName).newInstance();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           
            throw new BusinessException("Factory Failed");
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        }
	}
	
	public static GraphService createGraphService() throws BusinessException
	{
		ResourceBundle resourceBundle = ResourceBundle.getBundle("BusinessFactory");
        
        String GraphServiceFullyQualifiedName = resourceBundle.getString("GraphService");
        
        System.out.println(GraphServiceFullyQualifiedName);
        try {
            return (GraphService)Class.forName(GraphServiceFullyQualifiedName).newInstance();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           
            throw new BusinessException("Factory Failed");
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new BusinessException("Factory Failed");
        }
	}
}
